# 获取所哟的城市


import urllib.request

# 1. 创建请求对象，编码
url = "https://dianying.taobao.com/cityAction.json?activityId&_ksTS=1710917324404_108&jsoncallback=jsonp109&action=cityAction&n_s=new&event_submit_doGetAllRegion=true"
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0",
    'Cookie': 'miid=882487351413759028;cookie2=155ced138344c9c33ed1367bc1d8d780;t=b3c1bc47d789ef29a7acc08335992448;_tb_token_=78d13051be5fb;tk_trace=oTRxOWSBNwn9dPyorMJE%2FoPdY8zMG1aAN%2F0TkjYGZjkj6rrK3kv4LgxGhtlxvv5DK7IDZ6l3hkJe5jbhCoTbGeS%2FPUTijhaDryj0QlSQoffNq2L1%2BSSOTvEB9UDhKwbd7X9AGW96zoIKxR%2FCYKQJUImhyWIXuCr0j5aWC9tLt9y6m5D0dA91kTwGReJRV%2Fonq5JcZpGsH0cs9FStygj58J2bD2xwILBtf9KpEbJbWsbKHALWdmLrF3S9AIpjDAgZKyAuJnZ2I4x1TqAwIS6jLgpUQ4oFa3uZV8h%2BTPW%2BQb08FtCWBEKmMeONB2vpXja9fMR7DxRhSodzJJ66ZVVSom48O72RNSoGKtdH1jAO5weA%2Bk7eIdMuNObhCra6tHUTAXympf4JykgZW7KTOcshGneq50bC69sB7EQ37udNjhbw573Gg8w%2Fsr6zqpN1I%2BRb368vNFB1KES5mSJnsG681hfG79LApWjzaZTX5iWORWIgRPjYauHlfhoqWIHm%2BIoa1y0C4Dc%2BzBg%3D;_samesite_flag_=true;v=0;cna=s3SBHj/dN24BASQJigDVZ3/6;xlly_s=1;isg=BOzsPyQspUXE9bF5cK74HJ3avcoepZBPTLUoBUYtiBc6UYxbbrWk37bncRlpBMin',
    "Referer":"https://dianying.taobao.com/"
}

request = urllib.request.Request(url, headers=headers)

# 2.发送请求，返回响应
response = urllib.request.urlopen(request)
# 3.读取信息，解码
content = response.read().decode("utf8") # type:str
import json
import jsonpath

# print(content[content.index("(") + 1:-2])
cities_json = json.loads(content[content.index("(") + 1:-2])
citys_list = jsonpath.jsonpath(cities_json, "$.returnValue..regionName")
print(citys_list)
